<%--
  Created by IntelliJ IDEA.
  User: 曹子阳
  Date: 2021/5/31
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加标签</title>
</head>
<body>
<p class="layui-anim layui-anim-upbit mc-ui-flex-end" style="text-align:center;
    font-size:18px">
    &nbsp;
</p>
<input id="lable" name="lable" class="layui-input layui-anim layui-anim-upbit" type="text" autocomplete="off"
       placeholder="请输入标签名称"/>
<p class="layui-anim layui-anim-up mc-ui-flex-end" style="text-align:center;
    font-size:18px">
    &nbsp;
</p>
<textarea name="textarea" class="layui-textarea layui-anim layui-anim-up" placeholder="一段话描述标签"></textarea>
<p class="layui-anim layui-anim-up mc-ui-flex-end" style="text-align:center;
    font-size:18px">
    &nbsp;
</p>
<a lay-submit="insert" lay-filter="insert" onclick="insert()"
   class="layui-btn layui-btn-radius layui-btn-fluid layui-btn-normal layui-anim layui-anim-scale">提交</a>
</body>
</html>
<script>
    window.insert = function () {
        layui.use(['jquery'], function () {
            var $ = layui.jquery,
                lable = $(`input[name='lable']`).val(),
                textarea = $('textarea').val();

            if (lable == '') {
                layer.msg('标签不能为空');
                return false;
            }

            if (textarea == '') {
                layer.msg('描述不能为空');
                return false;
            }

            layer.confirm("确认要添加吗",function (index) {
                layer.close(index);

                // 所有的文章都可以选中默认标签
                $.ajax({
                    type:"post",
                    url:"/label.api/add",
                    data:{
                        name:lable,
                        describe:textarea
                    },
                    success:function (reg) {
                        reg.code == 1 ? layer.msg(reg.msg) : layer.msg(reg.msg);
                    }
                })
            })
        })
    }


</script>